using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// UI管理类
/// </summary>
public class UIManager : SingLetion<UIManager>
{
    Dictionary<string, UIBase> dicUi = new Dictionary<string, UIBase>();

    public void OpenUI(string panelName)
    {
        UIBase uIBase;
        uIBase = LoadUI(panelName);
        uIBase.Show();
    }

    private UIBase LoadUI(string panelName)
    {
        UIBase TempUI;
        if (!dicUi.TryGetValue(panelName, out TempUI))
        {
            GameObject obj = Resources.Load<GameObject>(panelName.ToString());
            if (obj != null)
            {
                GameObject go = GameObject.Instantiate(obj, GameObject.Find("Canvas/UiParent").transform);
                TempUI = go.GetComponent<UIBase>();
                if (TempUI != null)
                {
                    dicUi.Add(panelName, TempUI);
                    dicUi[panelName].Init();
                }
            }
        }
        return TempUI;
    }

    public void CloseUI(string paneLName)
    {
        if (dicUi.ContainsKey(paneLName))
        {
            dicUi[paneLName].Hide();
        }
    }
}
